//
//  MeController.m
//  庐山通
//
//  Created by mac22 on 14/10/19.
//  Copyright (c) 2014年 郑朝军. All rights reserved.
//

#import "MeController.h"
#import "ItemGroup.h"
#import "MeTableViewCell.h"
#import "Item.h"
#import "ArrayItem.h"
#import "MyNavigation.h"

@implementation MeController

- (NSMutableArray *)groupArray
{
    if (_groupArray == nil) {
        _groupArray = [[NSMutableArray alloc]init];
    }
    return _groupArray;
}
// new一个group
- (ItemGroup *)addGroup
{
    ItemGroup * itemGroup = [ItemGroup group];
    [self.groupArray addObject:itemGroup];
    return itemGroup;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
}
// 有多少组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

// 每一组有多少个
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    ItemGroup * items = self.groupArray[section];
    return items.items.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MeTableViewCell * cell = [MeTableViewCell MeTableViewCell:tableView];
    ItemGroup * group = self.groupArray[indexPath.section];
    
    cell.itemsTitle = group.items[indexPath.row];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ItemGroup * group = self.groupArray[indexPath.section];
    Item * item = group.items[indexPath.row];
    
    if ([item isKindOfClass:[ArrayItem class]]) {
        ArrayItem * arrowItem = (ArrayItem*)item;
        if (arrowItem.destVcClass) {
            UIViewController * destVc = [[arrowItem.class alloc]init];
            destVc.title = arrowItem.title;
           // MyNavigation * nav = [[MyNavigation alloc]initWithRootViewController:destVc];
           // [self presentViewController:nav animated:YES completion:nil];
        }
    }
    

}
@end
